﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MaxLeaf.KH.DataContract;
using System.Transactions;

using System.Data.SqlClient;
using MaxLeaf.KH.DALImplementation;
using System.Collections;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Dictionary<string, object> inputData = null;
            //Dictionary<string, object> outputData = null;
            //string cmd = string.Empty;

            //MaxLeaf.KH.WebProxy.Proxy proxy = new MaxLeaf.KH.WebProxy.Proxy();

            //cmd = "SelectDtl";
            //inputData = new Dictionary<string, object>();
            //inputData["data"] = new TestModel { Name="adasd"};
            //inputData["KeyValue"] = 1;
            //outputData = (Dictionary<string, object>)proxy.Execute(cmd, inputData);
            //List<object> list = (List<object>)outputData["data"];
            //TextBox1.Text = ((TestModel)list[0]).Name;

            //TestModel user = new TestDAL().Read<TestModel>(9);
            //TextBox1.Text = user.Name;

            //using (TransactionScope tx = new TransactionScope())
            //{
            //    try
            //    {


            //        using (SqlConnection conA = new SqlConnection("Data Source=z-win2003;Initial Catalog=test;User Id=sa;Password=123456;"))
            //        {
            //            conA.Open();
            //            SqlCommand cmd = conA.CreateCommand();
            //            cmd.CommandText = "insert into a(name) values('1')";
            //            cmd.ExecuteNonQuery();

            //        }
            //        using (SqlConnection conB = new SqlConnection("Data Source=z-win2003b;Initial Catalog=test;User Id=sa;Password=123456;"))
            //        {
            //            conB.Open();
            //            SqlCommand cmd = conB.CreateCommand();
            //            cmd.CommandText = "insert into a(name) values('2')";
            //            cmd.ExecuteNonQuery();

            //        }


            //        tx.Complete();

            //    }
            //    catch
            //    {

            //        throw;
            //    }
            //    finally
            //    {



            //    }

            //}
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            MaxLeaf.KH.WebProxy.Proxy proxy = new MaxLeaf.KH.WebProxy.Proxy();
             Dictionary<string,object> inputData=new Dictionary<string,object>();
             TestModel user = new TestModel();
             user.Name = TextBox1.Text;
            inputData["data"]=user;
            Dictionary<string, object> outputData = (Dictionary<string, object>)proxy.Execute(Button1.Text, inputData);

            if (outputData.ContainsKey("error") && outputData["error"] != null)
            {
                Label1.Text = string.Format("发生错误： {0}", outputData["error"].ToString());
            }
            else
            {
                Label1.Text = ((TestModel)outputData["data"]).Name;
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            MaxLeaf.KH.WebProxy.Proxy proxy = new MaxLeaf.KH.WebProxy.Proxy();
            Dictionary<string, object> inputData = new Dictionary<string, object>();
            inputData["data"] = TextBox1.Text;
            Dictionary<string, object> outputData = (Dictionary<string, object>)proxy.Execute(Button2.Text, inputData);

            if (outputData.ContainsKey("error") && outputData["error"] != null)
            {
                Label1.Text =string.Format("发生错误： {0}", outputData["error"].ToString());
            }
            else
            {
                Label1.Text = outputData["data"].ToString();
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            
        }
    }
}